package bg.btanev.eightyfour.domain.experience.institution;

import org.apache.commons.lang.Validate;

import bg.btanev.eightyfour.domain.entitybase.DomainEntity;
import bg.btanev.eightyfour.domain.person.ContactInfo;

/**
 *
 * @author B.Tanev
 *
 */
public abstract class Institution extends DomainEntity<Long> {
	/**
	 *
	 */
	private static final long serialVersionUID = -1517070313023787696L;

	private String name; // not null; unique?!
	private ContactInfo contactInfo; // component, not null

	protected Institution() {
		super();
	}

	public Institution(String name, ContactInfo contactInfo) {
		this(null, name, contactInfo);
	}

	public Institution(Long id, String name, ContactInfo contactInfo) {
		super(id);

		Validate.notEmpty(name, "Experiance institution name cannot be empty.");
		Validate.notNull(contactInfo, "Experiance institution contact info cannot be null.");

		this.name = name;
		this.contactInfo = contactInfo;
	}

	public ContactInfo getContactInfo() {
		return contactInfo;
	}

	public String getName() {
		return name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((contactInfo == null) ? 0 : contactInfo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Institution other = (Institution) obj;
		if (contactInfo == null) {
			if (other.contactInfo != null)
				return false;
		} else if (!contactInfo.equals(other.contactInfo))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Institution [contactInfo=" + contactInfo + ", name=" + name + ", toString()=" + super.toString() + "]";
	}
}
